<?php

namespace models;
class Config extends BaseModel {
    protected $logName = '配置';
    // 类型格式化
    const TypesFormat = [
    	1 => '普通文本' ,
		2 => 'json' ,
		3 => '图片' ,
	];
    const NORMAL_TEXT = 1;
    const JSON_TEXT = 2;
    const IMAGE_TEXT = 3;

	/**
	 * 获取配置
	 * @return bool|mixed
	 * @author Colin <amcolin@126.com>
	 * @date 2022-01-22 下午4:57
	 */
    public function getConfigs(){
    	$list = $this->field('name,type,value')->select();
    	$host = $this->where(['name' => 'hosts'])->field('value')->find();
    	$newConfigs = [];
    	foreach ($list as $val){
    		$value = $val['value'];
			if ($val['type'] == self::JSON_TEXT){
				$value = json_decode($value , true);
			}else if ($val['type'] == self::IMAGE_TEXT){
				$value = $host['value'] . ltrim($value , '/');
			}
			$newConfigs[$val['name']] = $value;
		}

    	return $newConfigs;
	}
}
